home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / uhren & terminkalender / time / sunclock / source / options.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  3KB  |  127 lines

  1. /*-------------------------------------------------------------------------
  2.     SunClock
  3.  
  4.     Amiga version by Mark Waggoner, 
  5.     waggoner@ichips.intel.com or wagnell@PDaXcess.techbook.com
  6.     December 1991
  7.  
  8.     Options.c
  9.     Parse options for workbench or CLI use
  10. -------------------------------------------------------------------------*/
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include <stdlib.h>
  14. #include <functions.h>
  15. #include <workbench/startup.h>
  16. #include <workbench/workbench.h>
  17.  
  18. extern int AdjustIcon,FullScreen;
  19. extern struct NewWindow NewIconWindow;
  20. struct Library *IconBase;
  21.  
  22. /*-------------------------------------------------------------------
  23.     Skip past the next space delimited token in a string
  24. -------------------------------------------------------------------*/
  25. char *
  26. SkipToken(char *s) {
  27.     while(*s &&  isspace(*s)) s++;
  28.     while(*s && !isspace(*s)) s++;
  29.     return(s);
  30. }
  31.  
  32. /*-------------------------------------------------------------------
  33.     Check an option name for CLI parsing
  34. -------------------------------------------------------------------*/
  35. char *
  36. CheckOption(char *s,char *opt) {
  37.     int l,m;
  38.     char *t;
  39.  
  40.     l = strlen(opt);
  41.  
  42.     /* Find the length of the next word */
  43.     m = 0; t = s;
  44.     while(*t && !isspace(*t) && *t != '=') { t++; m++; }
  45.  
  46.     if (m!=l) 
  47.         s = NULL;
  48.     else
  49.     if (strncmp(s,opt,l))
  50.         s = NULL;
  51.     else {
  52.         s+=l;
  53.         /* Skip past an equal sign */
  54.         while(*s && isspace(*s)) s++;
  55.         if (*s == '=') s++;
  56.     }
  57.     return(s);
  58. }
  59.  
  60. /*-------------------------------------------------------------------
  61.     I parse the cli parameters before they get to main()
  62. -------------------------------------------------------------------*/
  63. void
  64. _cli_parse(struct Process *pp, long alen, register char *aptr)
  65. {
  66.     char *s,*t;
  67.  
  68.     s = aptr;
  69.  
  70.     while(*s) {
  71.         while(*s && isspace(*s)) s++;
  72.         if (t = CheckOption(s,"TOP")) {
  73.             NewIconWindow.TopEdge = atoi(t);
  74.             s = SkipToken(t);
  75.         }
  76.         else
  77.         if (t = CheckOption(s,"LEFT")) {
  78.             NewIconWindow.LeftEdge = atoi(t);
  79.             s = SkipToken(t);
  80.         }
  81.         else
  82.         if (t = CheckOption(s,"DONOTADJUST")) {
  83.             AdjustIcon = 0;
  84.             s = t;
  85.         }
  86.         else
  87.         if (t = CheckOption(s,"FULLSCREEN")) {
  88.             FullScreen = 1;
  89.             s = t;
  90.         }
  91.         else
  92.             s = SkipToken(s);
  93.     }
  94. }
  95.  
  96.  
  97. /*-------------------------------------------------------------------
  98.     Parse workbench options
  99. -------------------------------------------------------------------*/
  100. void
  101. _wb_parse(struct Process *pp,struct WBStartup *wbm)
  102. {
  103.     char *tool;
  104.     struct DiskObject *dob;
  105.  
  106.     CurrentDir(wbm->sm_ArgList->wa_Lock);
  107.  
  108.     if ((IconBase = OpenLibrary("icon.library", 0L)) == 0)
  109.         return;
  110.     if ((dob = GetDiskObject(wbm->sm_ArgList->wa_Name)) == 0)
  111.         goto NoDiskObj;
  112.  
  113.     if (tool = FindToolType(dob->do_ToolTypes, "TOP"))
  114.         NewIconWindow.TopEdge = atoi(tool);
  115.     if (tool = FindToolType(dob->do_ToolTypes, "LEFT"))
  116.         NewIconWindow.LeftEdge = atoi(tool);
  117.     if (tool = FindToolType(dob->do_ToolTypes, "DONOTADJUST"))
  118.         AdjustIcon = 0;
  119.     if (tool = FindToolType(dob->do_ToolTypes, "FULLSCREEN"))
  120.         FullScreen = 1;
  121.  
  122.     FreeDiskObject(dob);
  123. NoDiskObj:
  124.     CloseLibrary(IconBase);
  125.     IconBase = NULL;
  126. }
  127.